﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IntoNails.Infrastructure.ViewModels;
using IntoNails.Infrastructure.Views;
using IntoNails.Models;
using IntoNails.Modules.CustomerManagement.Models;

namespace IntoNails.Modules.CustomerManagement.ViewModels
{
    public class CustomerInteractionDialogViewModel : GenericInteractionViewModel<Customer>, IHeaderInfoProvider<string>
    {
        #region Fields

        private string _headerInfo;
        private UserType _selectedAuthority;

        private bool _isEditMode;
        private GenderType _selectedGender;

        #endregion

        public CustomerInteractionDialogViewModel()
        {
            
        }

        #region Commands

        ////public ICommand AddProductLinkCommand { get; private set; }
        ////public ICommand ProductLinkGridLoadedCallbackCommand { get; private set; }

        #endregion

        #region Implementation of IHeaderInfoProvider<string>

        public string HeaderInfo
        {
            get { return this._headerInfo; }
            set
            {
                this._headerInfo = value;
                base.RaisePropertyChanged(() => HeaderInfo);
            }
        }

        #endregion

        #region Properties

        public bool IsEditMode
        {
            get { return this._isEditMode; }
            set
            {
                this._isEditMode = value;
                base.RaisePropertyChanged(() => IsEditMode);
            }
        }

        public IEnumerable<GenderType> GenderValues
        {
            get
            {
                return Enum.GetValues(typeof(GenderType)).Cast<GenderType>();
            }
        }

        public GenderType SelectedGender
        {
            get { return this._selectedGender; }
            set
            {
                this._selectedGender = this.InteractionEntity.Gender = value;
                base.RaisePropertyChanged(() => SelectedGender);
            }
        }

        #endregion

        public override void ViewInvoked(object parameter)
        {
            base.ViewInvoked(parameter);

            CustomerDataContext dataContext = parameter as CustomerDataContext;
            if (dataContext == null)
                throw new NullReferenceException("dataContext");

            this.SelectedGender = dataContext.Gender;
            this.IsEditMode = dataContext.IsEditMode;
            this.HeaderInfo = this.IsEditMode ? "Edit Customer" : "Add New Customer";
        }
    }
}
